package No301_400.No301_310.RangeSumQuery_Immutable_303;

public class NumArray {
	int[] nums;
	int[] sum;

    public NumArray(int[] nums) {
        this.nums = nums;
        this.sum = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
			sum[i] = (i==0)?nums[i]:sum[i-1]+nums[i];
		}
    }

    public int sumRange(int i, int j) {
    	if(i==0){
    	    return sum[j];
    	}else{
    	    return sum[j]-sum[i-1];
    	}
    }


// Your NumArray object will be instantiated and called as such:
// NumArray numArray = new NumArray(nums);
// numArray.sumRange(0, 1);
// numArray.sumRange(1, 2);
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
